Chapter 2: JavaScript Programming
The best way to get started with JavaScript programming, is having an understanding of programming paradigms. We should be able to differentiate between them. There are three paradigms; Functional programming, Object-oriented programming and Procedural programming. A paradigm is a set of concepts and standards that make up legitimate contributions to any given field. With regards to JavaScript, it’s really just how you write and arrange your code.
Functional Programming
Functional programming in JavaScript In this context, it is creating pure functions that focus solely on the outcome and not the process. Pure functions are immutable, which means you can’t change their state. They make use of conditional expressions and recursion when performing calculations. They do not rely on anything beyond their parameters, so they are predictable. If you have the same parameters, the outcome will always be the same. Recursion is a pattern that programmers use when a line of code can be split into several similar tasks but simpler.
Types of Functions
First class functions are treated as sole entities. They are independent. We can use them the same way we do data. Functional programming uses arguments, return values and variables as functions to create more intricate code. First class functions are relatively pliable so some Object Oriented languages incorporate them too.
Higher-Order Functions
Higher-order functions work on other functions and take them as arguments. They also return other functions as output.
Functional programming does not support loop statements or conditional statements like if.
What Are Conditional Statements?
Conditional statements look at the conditions in the JavaScript code and then make decisions based on that. Like the name suggests, a statement can either be true or false. The code only gets executed if the condition is true. There are four types of conditional statements:
     The if statement
Carries out part of the code if the condition is true.
     The else statement
Carries out the part of the code related to else if the condition is false.
     The else if statement
Designates and tests a new condition if the first if condition is false.
     The switch-case statement
Designates a number of substitute code blocks to be carried out based on specific conditions.
Object-Oriented Programming
JavaScript itself is not based in Object oriented language, but we can still use it when programming. While functional programming is centered around functions and logic, OOP or Object-oriented programming is not. It is a model that focuses more on objects. It is the process of organizing your data in classes and then in objects based on their class. In this case, an object is a data field with its own features and properties. OOP is good for bigger programs that require constant updating and maintenance. But that slows down their speed and results in them using a lot of memory.
Before anything, you want to start off with an understanding of data-modeling. Data modeling is when you take all the objects that you want to work with and compare them. If your object was cars, you would want to compare them by make, color and size.
The properties that make up Object-Oriented Programming are:
     Classes–Are the models used to create objects
     Objects–Are units that possess characteristics and can be organized by type
     Methods–Make JavaScript able to manipulate or change the data inside it
     Attributes–Are words we put in the start and end tags of html elements to control what the tag does
Objects
Objects are made up of characteristics. If one of the characteristics has a function, it’s considered a method. If it has no function then it’s just a property. A property can be any of the primitive data types, but they are usually variables located in objects.
The principles of OOP are:
     Encapsulation–Is a method used to hold vital information inside an object and prevent additional information from being exposed. It gives the other objects controlled access and aids in preventing any data corruption.
     Abstraction–Only shares pertinent attributes between objects and hides any unnecessary code
     Inheritance–Is the operation by which one class can obtain properties (like fields) from another
     Polymorphism–Is the process of representing one thing in different forms. In JavaScript it means that different objects can share the same attributes.
OOP is easier to manage and it can be likened to the real world so it’s easier to grasp.
Procedural Programming
Procedural programming has a direct approach to organizing code. It aims to break a program down into procedures. In this case, procedures are functions that are conducted chronologically. It tells the computer to perform functions in sequence until the desired outcome is reached.
Fundamental Features of Procedural Programming
     Predefined Functions
A Predefined function is a command identified by a name. They are incorporated in complex programming languages but they are stored in the JavaScript library and not the program itself.
     Local Variable
A local Variable is stated in the main structure of a method and cannot exist outside of a certain field. Local variables can only be used in the method they are written in. If a programmer attempted to write them outside of the method, the code would fail.
     Global Variable
Global variables are written outside of methods and can be used in all functions.
     Modularity
Modularity is when two different systems are tasked with different actions but get grouped together to perform a singular task first. Each group would perform their tasks in sequence until completion.
     Parameter Passing
Parameter passing is an operation used to pass guidelines to functions, subroutines or procedures. They can be executed through passing by value, reference, result and name.
Applications of JavaScript Programming
JavaScript can be found in nearly every aspect of software development. Some aspects include:
     HTML Manipulation
JavaScript allows you to add, remove, and change the appearance of any element of HTML to suit the requirements of any given device.
     User Notifications
It is critical to double-check user inputs before sending it to the server, so JavaScript verifies those inputs on the front end.
     Back-End Data Loading
Ajax library allows back-end data to load while other processing is happening. This ensures that there are no interruptions for the client.
     Presentations
JavaScript lets you construct presentations to enhance a website’s appearance.
     Server Applications
The Server Application is pretty much the same as the client application because they both deliver and receive data. The only difference between them is that they connect to the server differently.
     Client-Side Validation
Contributes to the overall user experience. It is an initial check that is run to identify any invalid data on the client-side so that the user can fix it.
A recurring term that we should expand on is the ‘client’.
Client-Side and Server-Side are expressions used to define where the application code is executed. In a ‘serverless’ framework, the vendor distributes resources to all processes that happen on the side of the server. Cloud service providers still make use of servers to run code for developers, so the name can be misleading.
The Client-Server Model is a framework located on the web. It divides computers into two sections. The first section requests services (the client) and the second section serves the clients (the server). A server is contained within a high performance computer, but it is not a computer itself. Servers are programs that aid in client functionality. The client-server model is a constant cycle of requests and responses. It is used because it has a larger capacity and is therefore more reliable than a user device.
Now that you have an idea of what programming actually entails, you are ready to learn about the skeleton of an application and what goes into constructing it.